package models;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Created by 郑凯 on 2016/6/14.
 */
public interface IUser {

    @Select("select * from user where (name = #{name} OR email = #{email}) AND password = #{password}")
    User GetUserByNameAndEmail(User user);
    @Select("SELECT * FROM  user where name = #{name}")
    User GetUserByName(User user);
    @Select("SELECT * FROM  user where email = #{email}")
    User GetUserByEmail(User user);
    @Select("SELECT * FROM  user where uid = #{uid}")
    User GetUserByUid(String uid);
    @Select("SELECT * FROM  daily WHERE uid = #{uid} ORDER  BY time DESC")
    List<daily> GetDailyByUid(String uid);
    @Select("SELECT * FROM  daily WHERE uid = #{uid} ORDER  BY time DESC limit #{begin},15")
    List<daily> GetDailyDispage(DailyDispage dispage);

    @Select("SELECT * FROM daily WHERE did = ${did}")
    daily GetDailyByDid(daily d);

    @Select("select count(*) from daily where uid = #{uid}")
    int SearchUserDaily(String uid);
    @Insert("INSERT INTO user(uid, name, password, email) VALUES (#{uid},#{name},#{password},#{email});")
    void InsertUser(User user);
    @Insert("insert into daily(did,title,content,time,uid,tab) values(#{did},#{title},#{content},#{time},#{uid},#{tab});")
    int insertDaily(daily d);
    @Update("update user set daily = #{daily} where uid = #{uid}")
    void UpdateUserDaily(User user);
    @Update("update daily set title = #{title},content=#{content}, tab = #{tab} where did = #{did}")
    void UpdateDailyByDid(daily d);
    @Delete("delete from daily where did = ${did}")
    void DeleteDailyByDid(daily d);
    @Update("update user set name = #{name},password = #{password},img = #{img} where uid = #{uid}")
    void UpdateUserByuid(User user);

}
